package com.ce.framework.util;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.HashMap;

import net.sf.json.JSONArray;

import com.ce.framework.util.node.APITreeNode;

public class APIUtil {

	public static void main(String[] args) throws IOException{
		System.out.println(new APIUtil().getApiTreeJson());
		OutputStreamWriter osw=new OutputStreamWriter(new FileOutputStream("jsAPI/tree.json"),"UTF-8");
		PrintWriter out = new PrintWriter(osw);
		out.println(new APIUtil().getApiTreeJson());
		out.close();
		osw.close();
		System.out.println(new APIUtil().getApiTreeJson());
	}
	
	private static String catalogs = "01_welcome.htm:首页,02_basic:基础,03_table:表格,04_window:弹出窗口,05_tree:树,06_combo:下拉选择,07_tag:自定义标签库";
	public static HashMap<String,String> cataMap = new HashMap<String, String>();
	static{
		for(String str:catalogs.split(",")){
			String[] tmp = str.split(":");
			cataMap.put(tmp[0], tmp[1]);
		}
	}
	public String getApiTreeJson() throws IOException{
		JSONArray ary = new JSONArray();
		File root = new File("jsAPI/apidoc");
		for(File f:root.listFiles()){
			if(".svn".equals(f.getName())){
				continue;
			}
			ary.add(new APITreeNode(f));
		}
		return ary.toString();
	}
}
